package com.example.njupt.base;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.example.njupt.base.mvp.BasePresenter;
import com.example.njupt.base.mvp.IView;
import com.example.njupt.okhttp.retrofit.BaseResult;

/**
 * Author:      mwang
 * Create Date: Created in 2021/4/26 11:34
 * Update Date:
 * Modified By:
 * Description:
 */
public abstract class BaseMvpActivity<P extends BasePresenter> extends BaseActivity implements IView {
    protected P mPresenter;
    public Context context;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        context = this;
        mPresenter = createPresenter();
        if (mPresenter != null) {
            mPresenter.attachView(this);
        }
        super.onCreate(savedInstanceState);
    }

    protected abstract P createPresenter();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.detachView();
        }
    }

    @Override
    public void showLoading() {
        showLoadingDialog();
    }

    @Override
    public void hideLoading() {
        hideLoadingDialog();
    }

    @Override
    public void showError(String msg) {

    }

    @Override
    public void onErrorCode(BaseResult result) {

    }
}
